/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package interface_graphique;

import ClassesJava.Utilisateur;
import connexion.ConnectionManager;
import static interface_graphique.MenuPrincipale.menu;


/**
 *
 * @author ISMAYLOULABBIHI
 *
 */
public class Authentification extends javax.swing.JFrame {
    public static Authentification at;
    public ConnectionManager c;
    public  Utilisateur ut;

    /**
     * Creates new form Authentification modification
     */
    public Authentification() {
        initComponents();
        setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtlogin = new javax.swing.JTextField();
        txtpasse = new javax.swing.JPasswordField();
        loginIn = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setUndecorated(true);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        txtlogin.setBorder(null);
        txtlogin.setName("txtlogin"); // NOI18N
        getContentPane().add(txtlogin, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 100, 170, 20));

        txtpasse.setBorder(null);
        txtpasse.setName("txtpasse"); // NOI18N
        getContentPane().add(txtpasse, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 170, 170, 20));

        loginIn.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        loginIn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                loginInMouseClicked(evt);
            }
        });
        getContentPane().add(loginIn, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 240, 130, 30));

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/qyite.png"))); // NOI18N
        jLabel2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel2MouseClicked(evt);
            }
        });
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(580, 0, 20, 20));

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/auto2.png"))); // NOI18N
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 600, 280));

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    //botton login
    private void loginInMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_loginInMouseClicked
        ut = new Utilisateur();
        boolean login = ut.logIn(txtlogin.getText(), txtpasse.getText());

        if (login == true) {
            menu = new MenuPrincipale();
            menu.setVisible(true);
            this.setVisible(false);
        } else {
            javax.swing.JOptionPane.showMessageDialog(null, "Nom d'utilisatuer ou le mot de passe incorecte", "Erreur Authentification", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }


    }//GEN-LAST:event_loginInMouseClicked

    private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel2MouseClicked
         dispose();
    }//GEN-LAST:event_jLabel2MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Authentification.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Authentification.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Authentification.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Authentification.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
               
               at= new Authentification();
               at.setVisible(true);

            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel loginIn;
    private javax.swing.JTextField txtlogin;
    private javax.swing.JPasswordField txtpasse;
    // End of variables declaration                                 
}
